<!-- 实验报告查询 -->
<template>
  <div>
    <div class="searchbox">
      <el-form :inline="true" size="small" label-width="100px">
        <jt-easy-collapse :has-expand="true">
          <template slot="expand">
            <el-form-item label="任务单号">
              <el-input size="small" v-model="form.taskNo" placeholder="任务单号"></el-input>
            </el-form-item>
            <!-- <el-form-item label="任务单状态"> -->
              <!-- <el-input size="small" v-model='form.taskStatus' placeholder="任务单状态"></el-input> -->
              <!-- <el-select v-model="form.taskStatus">
                <el-option :label="all" :value="' '"></el-option>
                <el-option
                  v-for="item in taskStatusList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item> -->
               <el-form-item label="热处理炉号">
                                          <el-input size="small" placeholder="热处理炉号" v-model='form.heatingNumber'></el-input>
                                        </el-form-item>
            <el-form-item label="零件图号">
              <el-input size="small" v-model="form.partGraphNumber" placeholder="零件图号"></el-input>
            </el-form-item>
            <el-form-item label="零件号">
              <el-input size="small" v-model="form.partNumber" placeholder="零件号"></el-input>
            </el-form-item>
            <el-form-item label="零件名称">
              <el-input size="small" v-model="form.partName" placeholder="零件名称"></el-input>
            </el-form-item>

            <el-form-item label="样品阶段">
              <!-- <el-input size="small" v-model='form.sampleStatusPhase' placeholder="样品阶段"></el-input> -->
              <el-select v-model="form.sampleStatusPhase" placeholder="请选择">
                                <el-option :label="all" :value="''"></el-option>

                <el-option
                  v-for="item in sampleStatusPhaseList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目号">
              <el-input size="small" v-model="form.projectNo" placeholder="项目号"></el-input>
            </el-form-item>
            <el-form-item label="报验批次信息">
              <el-input size="small" v-model="form.batchNumber" placeholder="报验批次信息"></el-input>
            </el-form-item>
            <el-form-item label="材料牌号">
              <el-input size="small" v-model="form.materialNo" placeholder="材料牌号"></el-input>
            </el-form-item>
            <el-form-item label="任务完成时间">
              <el-date-picker size="small" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" 
             v-model="qdate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px">
          </el-date-picker>
            </el-form-item>
            <el-form-item label="任务类型">

      <el-select v-model="form.taskType">
                <el-option :label="all" :value="''"></el-option>
                 <el-option :label="a" :value="'1'"></el-option>
                <el-option :label="b" :value="'2'"></el-option>
                <el-option :label="c" :value="'3'"></el-option>
              </el-select>
  </el-form-item>
  <el-form-item label="检验结论">

      <el-select v-model="form.testResult">
                <el-option :label="all" :value="''"></el-option>
                 <el-option :label="d" :value="'1'"></el-option>
                <el-option :label="e" :value="'0'"></el-option>
              </el-select>
  </el-form-item>
                 <!-- <el-form-item label="热处理炉号">
                                          <el-input size="small" placeholder="热处理炉号" v-model='form.heatingNumber'></el-input>
                                        </el-form-item> -->
            <el-form-item style="margin-left: 20px;">
              <el-button size="mini" type="primary" @click="refreshData">查询</el-button>
            </el-form-item>
            <el-form-item>
              <el-button size="mini" @click="clearForm">清除</el-button>
            </el-form-item>
          </template>
        </jt-easy-collapse>
      </el-form>
    </div>
    <div class="contentbox">
      <div style="float: left;padding-left: 20px;font-size: 15px;color: #666;padding-top: 6px;">
        委托单信息 共 <span style="color: red;">{{totalElements}}</span> 条数据
      </div>
      <el-row style="float: right;margin-right: 20px;margin-bottom: 15px;" type="flex" justify="end">
        <el-col>
          <jt-table-column-filter :table-key.sync="tableKey" :header-data.sync="tableHeaderArr" tableName='experimentalReportQuery' :filter-column.sync="filterColumnData"></jt-table-column-filter>
          <!-- <el-button size="small" type="primary" @click="lookReport">查看报告</el-button> -->
          <!-- <el-button size="small" type="primary">导出报告</el-button> -->
          <el-button size="small" type="primary" @click="getExcel()">导出清单</el-button>
        </el-col>
      </el-row>
      <!-- 查看报告 -->
      <look-entrust-report-display :show.sync="isShowEntrustdisplayReport" :taskId='reportId'></look-entrust-report-display>
      <look-entrust-report :show.sync="isShowEntrustReport" :taskId='reportId'></look-entrust-report>
      <el-dialog v-dialogDrag :show="isShowOperateLog" width="800px" append-to-body :close-on-click-modal="false" :visible.sync="isShowOperateLog">
        <operate-log :show.sync="isShowOperateLog" :taskId="orderid"></operate-log>
      </el-dialog>
      <!-- 表格 -->
      <el-table :data="tableData" :key='tableKey' v-loading="loading" @selection-change="handleSelectionChange" border stripe>
        <!-- <el-table-column type="selection" width="50" align="center" :resizable="false"></el-table-column> -->
        <el-table-column :index="indexMethod" type="index" label="序号" width="50" align="center" :resizable="false"></el-table-column>
        <el-table-column align="center" :key='item' v-for='item in filterColumnData' :resizable="false"
            :label="getTableHeaderLabel(item)"
            :prop="item"
            :min-width="getTableColumnWidth(item)"
            :fixed="getTableColumnFixed(item)"
            :sortable="getTableColumnSort(item)">
<template slot-scope="scope">
  <span v-if="scope.row.testResult==0" style="color:red">{{scope.row[item]}}</span>
  <span v-else>{{scope.row[item]}}</span>
  <el-button v-if="item === 'operate'" size="small" type="text" @click="displayReport(scope.row)">查看报告</el-button>
  <el-button v-if="item === 'operate'" size="small" type="text" @click="lookReport(scope.row)">电子报告</el-button>
  <!-- <el-button v-if="item === 'operate'" size="small" type="text" @click="getPdf(scope.row)">导出报告</el-button> -->
  <el-button
    v-if="item === 'operate'"
    size="small"
    type="text"
    @click="showOperateLog(scope.row)"
  >操作记录</el-button>
</template>
        </el-table-column>
      </el-table>


      <el-row type="flex" justify="center">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
          :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalElements"></el-pagination>
      </el-row>
    </div>
    </div>
  </div>
</template>

<script>
import { getAllReportListService, getSampleStatusPhase } from "service/task";
import { getLableFromList } from "utils/common";
import {
  APPLY_TYPE_LIST,
  RESULT_LIST,
  APPLY_STATUS_LIST,
  LIST_RESULT_LIST
} from "service/constant";
import JtTableColumnFilter from "components/jt-table-column-filter/index"; // 导入表格列筛选组件
import JtEasyCollapse from "components/jt-easy-collapse/index";
import LookEntrustReport from "dialog/experimental-management/experimental-report-query/look-entrust-report";
import LookEntrustDisplayReport from "dialog/experimental-management/experimental-report-query/look-entrust-report-display";
import OperateLog from "dialog/experimental-management/operate-log";
export default {
  name: "ExperimentalReportQuery",
  components: {
    "jt-table-column-filter": JtTableColumnFilter,
    "jt-easy-collapse": JtEasyCollapse,
    "look-entrust-report": LookEntrustReport,
    "look-entrust-report-display": LookEntrustDisplayReport,
    "operate-log": OperateLog
  },
  data() {
    return {
      tableKey: 1, // table key
      filterColumnData: [],
      sampleStatusPhaseList: [],
      qdate:"",
      orderid: "",
      isShowOperateLog: false,
         all:'全部',
        a:'委托型',
        b:'wip型',
        c:'非wip生产型',
        d:"合格",
        e:"不合格",
      form: {
        taskNo: "",
        testResult:"",
        taskStatus: "",
        partGraphNumber: "",
        partNumber: "",
        partName: "",
        heatingNumber:"",
        sampleStatusPhase:"",
        projectNo:"",
        batchNumber:"",
        materialNo:"",
        taskType:""
      },
      currentPage: 1,
      pageSizeArr: [10, 20, 50, 100],
      pageSize: 10,
      taskStatusList: [],
      all: "全部",
      tableHeaderArr: [
        {
          name: "acceptTime",
          alias: "任务单接取时间",
          // alias: "申请单提交时间",
          default: false,
          width: 170,
          fixed: false,
          sort: true
        },
        {
          // name: "reportTime",
           name: "auditTime",
          // alias: "报告生成时间",
          alias: "任务完成时间",
          default: false,
          width: 170,
          fixed: false,
          sort: true
        },
        {
          name: "applyTypeStr",
          alias: "任务类型",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "taskNo",
          alias: "任务单号",
          default: true,
          width: 200,
          fixed: false,
          sort: true
        },
        {
          name: "taskStatusStr",
          alias: "任务状态",
          default: true,
          width: 180,
          fixed: false,
          sort: true
        },
        {
          name: "heatingNumber",
          alias: "热处理炉号",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "partNumber",
          alias: "零件号",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "partGraphNumber",
          alias: "零件图号",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "projectNo",
          alias: "项目号",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "sampleStatusPhaseStr",
          alias: "样品阶段",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "materialNo",
          alias: "材料牌号",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "batchNumber",
          alias: "报验批次信息",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "operateUserName",
          alias: "操作人",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "resultStr",
          alias: "检验结论",
          default: true,
          width: 120,
          fixed: false,
          sort: true
        },
        {
          name: "remark",
          alias: "备注",
          default: true,
          width: 150,
          fixed: false,
          sort: true
        },
        {
          name: "operate",
          alias: "操作",
          default: true,
          width: 260,
          fixed: "right",
          sort: false
        }
      ],
      loading: false,
      tableData: [],
      isShowEntrustReport: false,
      isShowEntrustdisplayReport: false,
      reportId: "",
      totalElements: 0,
      pageNumber: 1,
      sort: "",
      order: ""
    };
  },
  methods: {
    // 清除
    clearForm() {
      this.form = {};
      this.showList();
    },
    getExcel() {
      this.form.taskStatus = 11;
      let stDate = '';
      let edDate = '';
      if(this.qdate&&this.qdate != '') {
        stDate = this.qdate[0];
        edDate = this.qdate[1];
      }
      window.location.href =
        `${process.env.API_URL}` +
        "task/allReportExcel?taskNo=" +
        this.form.taskNo +
        "&heatingNumber=" +
        this.form.heatingNumber +
        "&partGraphNumber=" +
        this.form.partGraphNumber +
        "&partNumber=" +
        this.form.partNumber +
        "&partName=" +
        this.form.partName +
        "&sampleStatusPhase=" +
        this.form.sampleStatusPhase +
        "&projectNo=" +
        this.form.projectNo +
        "&batchNumber=" +
        this.form.batchNumber +
        "&materialNo=" +
        this.form.materialNo +
        "&applyStart=" +
        stDate +
        "&applyEnd=" +
        edDate +
        "&taskType=" +
        this.form.taskType + 
        "&taskStatus=" +
        this.form.taskStatus +
        "&testResult=" +
        this.form.testResult;
    },
    showOperateLog(row) {
      this.orderid = row.id;
      this.isShowOperateLog = true;
    },
    getPdf(row) {
      window.location.href =
        `${process.env.API_URL}` + "pdf/download/" + row.id;
    },
    indexMethod(index) {
      return index + this.pageSize * (this.currentPage - 1) + 1;
    },
    refreshData() {
      let startDate = '';
      let endDate = '';
      if(this.qdate&&this.qdate != '') {
        startDate = this.qdate[0];
        endDate = this.qdate[1];
      }
      getAllReportListService({
        ...this.form,
        applyStart:startDate,
        applyEnd:endDate,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        sort: this.sort,
        order: this.order
      }).then(res => {
        console.log(res);
        this.tableData = res["data"]["result"]["content"];
        this.totalElements = res["data"]["result"]["totalElements"];
        // this.currentPage = res.data.result.pageable.pageNumber;
        this.pageNumber = res.data.result.pageable.pageNumber;
        this.pageSize = res.data.result.pageable.pageSize;
        this.tableData.forEach(e => {
          e.operateUserName = e.operateUser ? e.operateUser.name : "";
          e.sampleStatusPhaseStr = getLableFromList(
            this.sampleStatusPhaseList,
            e.sampleStatusPhase
          );
          e.resultStr = getLableFromList(LIST_RESULT_LIST, e.testResult);
          e.applyTypeStr = getLableFromList(APPLY_TYPE_LIST, e.taskType);
          e.taskStatusStr = getLableFromList(APPLY_STATUS_LIST, e.taskStatus);
        });
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.refreshData();
    },
    handleCurrentChange(val) {
      this.pageNumber = val;
      this.currentPage = val;
      this.refreshData();
    },
    // 显示报告
    displayReport(row) {
      this.isShowEntrustdisplayReport = true;
      this.reportId = row.id;
    },
    // 查看报告
    lookReport(row) {
      this.isShowEntrustReport = true;
      this.reportId = row.id;
    },
    // 获取表格多选的值
    handleSelectionChange(val) {},
    // 表头展示
    getTableHeaderLabel(str) {
      return this.getTableSomeValue(str, "alias");
    },
    // 获取表格列的宽度
    getTableColumnWidth(str) {
      return this.getTableSomeValue(str, "width");
    },
    // 获取表格列是否是固定的
    getTableColumnFixed(str) {
      return this.getTableSomeValue(str, "fixed");
    },
    // 获取表格列是否排序
    getTableColumnSort(str) {
      return this.getTableSomeValue(str, "sort");
    },
    // 获取表格表头，列宽度，列固定，列排序的值
    getTableSomeValue(str, keyName) {
      for (var value of this.tableHeaderArr) {
        if (value["name"] == str) {
          return value[keyName];
        }
      }
    }
  },
  mounted() {
    getSampleStatusPhase().then(res => {
      this.sampleStatusPhaseList = res.data.result;
    });
    this.taskStatusList = APPLY_STATUS_LIST;
    this.refreshData();
  }
};
</script>
